package com.example.sls.service.impl.account;

import com.example.sls.mapper.account.AccountMapper;
import com.example.sls.pojo.account.Account;
import com.example.sls.service.account.AccountService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class AccountServiceImpl implements AccountService {
    @Autowired
    AccountMapper accountMapper;

    @Override
    public Boolean addAccount(Account account) {
        boolean flag = false;
        if( accountMapper.addAccount(account) > 0){
            flag = true;
        }
        return flag;
    }

    @Override
    public Boolean updateAccount(Map<String, Object> account) {
        boolean flag = false;
        //System.out.println("account-AccountServiceImpl: " + account);
        if(accountMapper.updateAccount(account) > 0){
            flag = true;
        }
        return flag;
    }

    @Override
    public Boolean deleteAccount(Integer id) {
        boolean flag = false;
        if(accountMapper.deleteAccount(id) > 0){
            flag = true;
        }
        return flag;
    }

    @Override
    public Account getAccountById(Integer id) {
        return accountMapper.getAccountById(id);
    }

    @Override
    public Account getAccountByUserName(String username) {
        return accountMapper.getAccountByUserName(username);
    }

    @Override
    public List<Account> getAllAccount() {
        return accountMapper.getAllAccount();
    }



    @Override
    public Integer getCount() {
        return accountMapper.getCount();
    }

    @Override
    public Integer getMaxId() {
        return accountMapper.getMaxId();
    }

    @Override
    public PageInfo<Account> getAllAccountByPage(Integer pageNum, Integer pageSize) {

        PageHelper.startPage(pageNum, pageSize);
        List<Account> accounts = accountMapper.getAllAccount();
        PageInfo<Account> empPageInfo = new PageInfo<>(accounts);

        return empPageInfo;
    }
}
